package com.mall.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsHomeNewProductMapper;
import com.mall.model.domain.SmsHomeNewProduct;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【sms_home_new_product(新鲜好物表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class SmsHomeNewProductApiImpl extends ServiceImpl<SmsHomeNewProductMapper, SmsHomeNewProduct>
        implements SmsHomeNewProductApi {

    @Autowired
    private SmsHomeNewProductMapper smsHomeNewProductMapper;

    @Override
    public Page<SmsHomeNewProduct> listPage(Integer pageNum, Integer pageSize, String productName, Integer recommendStatus) {

        LambdaQueryWrapper<SmsHomeNewProduct> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(productName), SmsHomeNewProduct::getProductName, productName);
        lqw.eq(recommendStatus != null, SmsHomeNewProduct::getRecommendStatus, recommendStatus);
        lqw.orderByDesc(SmsHomeNewProduct::getSort);
        Page<SmsHomeNewProduct> page = new Page<>(pageNum, pageSize);

        return smsHomeNewProductMapper.selectPage(page, lqw);
    }

    @Override
    public List<SmsHomeNewProduct> findByIds(List<Long> ids, SmsHomeNewProduct homeNewProduct) {

        LambdaQueryWrapper<SmsHomeNewProduct> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), SmsHomeNewProduct::getId, ids);
        lqw.eq(SmsHomeNewProduct::getRecommendStatus, homeNewProduct.getRecommendStatus());

        return smsHomeNewProductMapper.selectList(lqw);
    }

    @Override
    public void updateByIds(List<Long> ids, SmsHomeNewProduct homeNewProduct) {

        LambdaQueryWrapper<SmsHomeNewProduct> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(ids), SmsHomeNewProduct::getId, ids);
        smsHomeNewProductMapper.update(homeNewProduct, lqw);
    }

    @Override
    public void updateSort(Integer id, SmsHomeNewProduct homeNewProduct) {

        LambdaQueryWrapper<SmsHomeNewProduct> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsHomeNewProduct::getId, id);
        smsHomeNewProductMapper.update(homeNewProduct, lqw);
    }

}




